use std::fmt;

use pest_ast::FromPest;

use crate::ast_define::Rule;

// ?关键字 9个
#[derive(Debug, PartialEq, FromPest)]
#[pest_ast(rule(Rule::CONST))]
pub struct CONST;

#[derive(Debug, PartialEq, FromPest)]
#[pest_ast(rule(Rule::INT))]
pub struct INT;

#[derive(Debug, PartialEq, FromPest)]
#[pest_ast(rule(Rule::VOID))]
pub struct VOID;

#[derive(Debug, PartialEq, FromPest)]
#[pest_ast(rule(Rule::IF))]
pub struct IF;

#[derive(Debug, PartialEq, FromPest)]
#[pest_ast(rule(Rule::ELSE))]
pub struct ELSE;

#[derive(Debug, PartialEq, FromPest)]
#[pest_ast(rule(Rule::WHILE))]
pub struct WHILE;

#[derive(Debug, PartialEq, FromPest)]
#[pest_ast(rule(Rule::BREAK))]
pub struct BREAK;

#[derive(Debug, PartialEq, FromPest)]
#[pest_ast(rule(Rule::CONTINUE))]
pub struct CONTINUE;

#[derive(Debug, PartialEq, FromPest)]
#[pest_ast(rule(Rule::RETURN))]
pub struct RETURN;

impl fmt::Display for CONST {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "const")
    }
}
impl fmt::Display for INT {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "int")
    }
}
impl fmt::Display for VOID {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "void")
    }
}
impl fmt::Display for IF {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "if")
    }
}
impl fmt::Display for ELSE {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "else")
    }
}
impl fmt::Display for WHILE {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "while")
    }
}
impl fmt::Display for BREAK {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "break")
    }
}
impl fmt::Display for CONTINUE {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "continue")
    }
}
impl fmt::Display for RETURN {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "return")
    }
}
